<?php require_once('/Connections/sepolwan_connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_ambil_berita = 4;
$pageNum_ambil_berita = 0;
if (isset($_GET['pageNum_ambil_berita'])) {
  $pageNum_ambil_berita = $_GET['pageNum_ambil_berita'];
}
$startRow_ambil_berita = $pageNum_ambil_berita * $maxRows_ambil_berita;

$colname_ambil_berita = "-1";
if (isset($_GET['sub'])) {
  $colname_ambil_berita = $_GET['sub'];
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_ambil_berita = sprintf("SELECT * FROM artikel WHERE jenis = %s ORDER BY id DESC", GetSQLValueString($colname_ambil_berita, "text"));
$query_limit_ambil_berita = sprintf("%s LIMIT %d, %d", $query_ambil_berita, $startRow_ambil_berita, $maxRows_ambil_berita);
$ambil_berita = mysql_query($query_limit_ambil_berita, $sepolwan_connect) or die(mysql_error());
$row_ambil_berita = mysql_fetch_assoc($ambil_berita);

if (isset($_GET['totalRows_ambil_berita'])) {
  $totalRows_ambil_berita = $_GET['totalRows_ambil_berita'];
} else {
  $all_ambil_berita = mysql_query($query_ambil_berita);
  $totalRows_ambil_berita = mysql_num_rows($all_ambil_berita);
}
$totalPages_ambil_berita = ceil($totalRows_ambil_berita/$maxRows_ambil_berita)-1;

$queryString_ambil_berita = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_ambil_berita") == false && 
        stristr($param, "totalRows_ambil_berita") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_ambil_berita = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_ambil_berita = sprintf("&totalRows_ambil_berita=%d%s", $totalRows_ambil_berita, $queryString_ambil_berita);
?>
<script type="text/javascript" src="<?php echo $base ?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo $base ?>js/jquery.blImageCenter.js"></script>
<script>
$(function(){
	$('.border img').centerImage();
})
</script>
<style>
.border{
	width:173px;
	height:98px;
	float:left;
	padding:4px;
	background:#fff;
	margin-right:10px;
	border:1px solid #006600;
}
.border span{
	width:173px;
	height:98px;
	float:left;
	overflow:hidden;
}
</style>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:10px;">
  <tr>
    <td width="685" valign="top"><table width="685" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="<?php echo $base ?>images/slideb.JPG"  /></td>
      </tr>
      <tr>
        <td valign="top"><div id="judul"><strong>Berita <?php echo $_GET['sub'] ?> </strong></div></td>
      </tr>
      <tr>
        <td valign="top"><?php if ($totalRows_ambil_berita > 0) { // Show if recordset not empty ?>
  <?php do { ?>
    <strong style="font-size:14px"><a href="<?php echo $base ?>detail-<?php echo $row_ambil_berita['id']; ?>/<?php echo str_replace(array(' ', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '{', '}', '|', ',', ':', ';', '"', '<', '>', ',', '.', '?', '/'), '-', $row_ambil_berita['judul']); ?>.html"><?php echo $row_ambil_berita['judul']; ?></a></strong><br />
    <?php echo tgl_indo($row_ambil_berita['waktu']); ?> | dilihat: <?php echo $row_ambil_berita['view']; ?> orang | komentar: <?php echo $row_ambil_berita['comment']; ?>
    <div style="width:100%; height:118px; margin-top:10px; text-align:justify">
      <div class="border">
        <span><img src="<?php echo $base ?>images/artikel/small/<?php echo $row_ambil_berita['image']; ?>" /></span></div>
      <div style="text-align:justify; margin-bottom:10px"><?php echo $row_ambil_berita['desk']; ?> <a href="<?php echo $base ?>detail-<?php echo $row_ambil_berita['id']; ?>/<?php echo str_replace(array(' ', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '{', '}', '|', ',', ':', ';', '"', '<', '>', ',', '.', '?', '/'), '-', $row_ambil_berita['judul']); ?>.html"><br />
        [selengkapnya]</a></div>
    </div>
    <div style="width:100%; height:1px; background:#CCC; margin-bottom:20px"></div>
    <?php } while ($row_ambil_berita = mysql_fetch_assoc($ambil_berita)); ?>
            <?php } // Show if recordset not empty 
			else { echo "<div align='center'>&rdquo; Maaf Post Masih Kosong &rdquo;</div>"; } ?>
<table border="0" align="center">
    <tr>
      <td><?php if ($pageNum_ambil_berita > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_ambil_berita=%d%s", $currentPage, 0, $queryString_ambil_berita); ?>">First</a>
          <?php } // Show if not first page ?></td>
      <td><?php if ($pageNum_ambil_berita > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_ambil_berita=%d%s", $currentPage, max(0, $pageNum_ambil_berita - 1), $queryString_ambil_berita); ?>">Previous</a>
          <?php } // Show if not first page ?></td>
      <td><?php if ($pageNum_ambil_berita < $totalPages_ambil_berita) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_ambil_berita=%d%s", $currentPage, min($totalPages_ambil_berita, $pageNum_ambil_berita + 1), $queryString_ambil_berita); ?>">Next</a>
          <?php } // Show if not last page ?></td>
      <td><?php if ($pageNum_ambil_berita < $totalPages_ambil_berita) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_ambil_berita=%d%s", $currentPage, $totalPages_ambil_berita, $queryString_ambil_berita); ?>">Last</a>
          <?php } // Show if not last page ?></td>
    </tr>
  </table></td>
        </tr>
    </table></td>
    <td width="10">&nbsp;</td>
    <td width="10" style="border-left:1px #ccc solid;" ></td>
    <td width="295" valign="top">
<?php include "samping_kanan/terpopuler.php" ?><br />
<img src="<?php echo $base ?>/images/adssmpng.jpg" width="290" /><br /><br />
<img src="<?php echo $base ?>/images/adskcl.jpg" width="290" /></td>
  </tr>
</table>
<?php
mysql_free_result($ambil_berita);
?>
